<?php

function getRandStr($len=7)
{
	$str = "";

	$selectStr = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";

	for ($i=0; $i <$len ; $i++) { 
		$index = mt_rand(0,strlen($selectStr)-1);
		$str .= $selectStr[$index];
	}

	return $str;
	
}


function changeLowerUpper($str=null)
{
	if(!$str){
		return "error,pra must";
	}

	for ($i=0; $i <strlen($str) ; $i++) { 
		if($str[$i]==strtoupper($str[$i])){
			$str[$i] = strtolower($str[$i]);
		}else{
			$str[$i] = strtoupper($str[$i]);
		}
	}

	return $str;
	
}

function get_max_long_son_arr($arr)
{
	$index = 0;
	$len = 0;
	foreach ($arr as $k => $v) {
		if(is_array($v)){
			if(count($v)>$len){
				$len = count($v);
				$index = $k;
			}
		}
	}
	return $arr[$index];
}


function changeOu($arr)
{
	foreach ($arr as $k => $v) {
		if(is_array($v)){
			$arr[$k] = changeOu($v);
		}else{
			if($v%2==1){
				$arr[$k] = $v*2;
			}
		}
	}
	return $arr;
}
/**
 * [Ftime 格式化时间]
 * @param [int] $time [时间戳]
 */
function Ftime($time)
{
	$diff = time()-$time;
	if($diff<60){
		return "刚刚";
	}elseif($diff<3600){
		return floor($diff/60)."分钟前";
	}elseif($diff<86400){
		return floor($diff/3600)."小时前";
	}elseif($diff<(86400*7)){
		return floor($diff/86400)."天前";
	}else{
		return date("Y-m-d H:i:s",$time);
	}
}
/**
 * [Fsize 格式化单位]
 * @param [int] $size [字节数]
 */
function Fsize($size)
{
	if($size<1024){
		return $size.'b';
	}elseif($size<pow(1024,2)){
		return round($size/1024,2).'kb';
	}elseif($size<pow(1024,3)){
		return round($size/pow(1024,2),2).'mb';
	}elseif($size<pow(1024,4)){
		return round($size/pow(1024,3),2).'gb';
	}else{
		return round($size/pow(1024,4),2).'tb';
	}
}
/**
 * [getRandNum 产生随机数]
 * @param  [arr] $max_min [范围]
 * @param  [int] $num     [个数]
 * @return [arr]          [随机数组]
 */
function getRandNum($max_min=[1,47],$num=7)
{
	$temp = [];

	for ($i=0; $i < $num ; $i++) { 
		
		$n = mt_rand($max_min[0],$max_min[1]);

		if(in_array($n,$temp)){
			$i--;
		}else{
			array_push($temp,$n);
		}
	}

	return $temp;

}
/**
 * [getMax 找最大值]
 * @param  [arr] $arr [数组]
 * @return [int]      [最大的数]
 */
function getMax($arr)
{
	if(!is_array($arr)){
		return false;
	}

	$max = $arr[0];

	foreach ($arr as $v) {
		if($v>$max){
			$max = $v;
		}
	}

	return $max;
}
/**
 * [config 读配置的全局函数]
 * @param  [string] $key [配置项]
 * @return [type]      [description]
 */
function config($key=null)
{
	$configs = include COMMON_PATH.'/configs.php';

	if($key){

		if(isset($configs[$key])){
			return $configs[$key];
		}else{
			return;
		}
		
	}else{
		return $configs;
	}
}